package com.victualler.product.goods.controller.impl;

import com.victualler.core.base.controller.impl.BaseRestControllerImpl;
import com.victualler.core.common.dto.PageDto;
import com.victualler.product.goods.controller.GoodsController;
import com.victualler.product.goods.entity.GoodsMainDao;
import com.victualler.product.goods.dto.GoodsDto;
import com.victualler.product.goods.dto.request.GoodsShowRequestDto;
import com.victualler.product.goods.repository.GoodsMainQueryRepository;
import com.victualler.product.goods.repository.GoodsMainRepository;
import com.victualler.product.goods.service.GoodsMainService;
import com.victualler.product.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product/goods")
public class GoodsControllerImpl  extends BaseRestControllerImpl<GoodsMainDao,GoodsMainRepository,GoodsMainQueryRepository,GoodsMainService> implements GoodsController {
    @Autowired
    private GoodsService goodsService;

    @RequestMapping("saveGoods")
    @Override
    public GoodsDto saveGoods(@RequestBody GoodsDto goodsDto) {
        this.goodsService.save(goodsDto);
        return goodsDto;
    }


    @RequestMapping("updateGoods")
    @Override
    public GoodsDto updateGoods(@RequestBody GoodsDto goodsDto) {
        //更新 保存
        this.goodsService.updateGoodsDto(goodsDto);
        return goodsDto;
    }

    @RequestMapping("getGoods/{id}")
    @Override
    public GoodsDto getGoodsById(@PathVariable("id") Long id) {
        return this.goodsService.getByGoodsId(id); //将存储后的结果返回
    }

    /**
     * @author Guoshichang
     * @since 13:39 on 2018/7/7.
     * @param goodsShowRequestDto
     * @param pageNo
     * @param limit
     * @Function  根据条件入参PermissionRequestDto动态分页查询权限
     */
    @RequestMapping("/getGoodsByRequestDto")
    public PageDto<GoodsMainDao> getGoodsByRequestDto(@RequestBody GoodsShowRequestDto goodsShowRequestDto, @RequestParam("pageNo") int pageNo, @RequestParam("limit") int limit) {
        return this.baseService.getGoodsByRequestDto(goodsShowRequestDto,pageNo,limit);
    }

    /**
     * @author Guoshichang
     * @since 13:39 on 2018/7/7.
     * @param goodsShowRequestDto
     * @param pageNo
     * @param limit
     * @Function  专门为微信小程序首页放开的后端接口 可以跳过登录验证
     */
    @RequestMapping("/getGoodsByRequestDtoByIndex")
    public PageDto<GoodsMainDao> getGoodsByRequestDtoByIndex(@RequestBody GoodsShowRequestDto goodsShowRequestDto, @RequestParam("pageNo") int pageNo, @RequestParam("limit") int limit) {
        return this.baseService.getGoodsByRequestDto(goodsShowRequestDto,pageNo,limit);
    }


    /**
     * @author Guoshichang
     * @since 21:05 on 2018/12/7.
     * @Function  统一刷条形码
     */
    @RequestMapping("/flushModelBarId")
    public void flushModelBarId() {
        this.goodsService.flushModelBarId();
    }
}
